package com.jiepos.mpos.common.dao;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.stereotype.Repository;

import com.jiepos.mpos.common.constant.DBConstant.Table;
import com.jiepos.mpos.common.constant.SystemConstant;
import com.jiepos.mpos.common.entity.App_Custom_InfEntity;
import com.jiepos.mpos.core.dao.BaseDao;

/**
 * 
 * 会员信息dao层
 * @ProjectName:  [mpos1] 
 * @Package com.jiepos.mpos.common.dao 
 * @author 肖志伟
 * @version 1.0
 * @since 2017年9月21日 下午5:59:25
 * @history（历次修订内容、修订人、修订时间等）
 * @UpdateRemark [说明本次修改内容]
 * 新增接口(杨剑武)
 * 通过会员查询对应机构相关信息接口
 * 通过会员查询对应卡相关信息接口
 * @Copyright (c) 2017 江苏杰博实信息技术有限公司
 */
@Repository
public class AppCustomerInfoDao extends BaseDao<App_Custom_InfEntity> {
	
	/**
	 * 批量修改用户状态
	 * @param string
	 * @param customer_uuids
	 * @param userSt
	 * @param valueOf
	 */
	public void updateByIds(String param, String customer_uuids, String userSt, String updateuser) {
		final String[] ids = customer_uuids.split(",");
		String sql = " UPDATE " +Table.T_APP_CUSTOM_INF + " SET USER_ST='"
				+ userSt + "',CHECK_LOGIN_COUNT = '0' , REC_UPD_TS=SYSTIMESTAMP ,rec_upd_usr_id='"+updateuser+"', last_oper_in='" + SystemConstant.OPER_UPDATE
				+ "' WHERE " + param + " = ?";
		log.debug("updateByIds sql : " + sql);
		log.debug("updateByIds ids: " + ids);
		jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
			@Override
			public int getBatchSize() {
				return ids.length;
			}
			@Override
			public void setValues(PreparedStatement arg0, int arg1) throws SQLException {
				arg0.setString(1, ids[arg1]);
			}
		});
		
	}

	public int insertCustomParm(String sql,List<Object> params){
		return jdbcTemplate.update(sql, params.toArray(new Object[params.size()]));
	}

	/**
	 * 批量修改会员机构
	 * 会员uuid,机构编号ins_uuid
	 * 最后修改人
	 */
	public void updateByCustomIds(String param, String custom_uuids,String ins_uuid,String updateuser ) {
		final String[] ids = custom_uuids.split(",");
		String sql = " UPDATE " + SystemConstant.TBL
				+ App_Custom_InfEntity.class.getSimpleName().replace(SystemConstant.TBL_SUFFIX, "") + " SET INS_UUID='"
				+ ins_uuid + "' , REC_UPD_TS=SYSTIMESTAMP ,rec_upd_usr_id='"+updateuser+"', last_oper_in='" + SystemConstant.OPER_UPDATE
				+ "' WHERE " + param + " = ?";
		log.debug("updateByIds sql : " + sql);
		log.debug("updateByIds ids: " + ids);
		jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

			@Override
			public int getBatchSize() {
				return ids.length;
			}

			@Override
			public void setValues(PreparedStatement arg0, int arg1) throws SQLException {
				arg0.setString(1, ids[arg1]);
			}

		});
	}
}

